<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>Right</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/resources/favicon.ico">
    <link rel="stylesheet" href="resources/layui/css/layui.css" th:href="@{/resources/layui/css/layui.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/resources/css/public.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/resources/layui_ext/dtree/dtree.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/resources/layui_ext/dtree/font/dtreefont.css}" media="all"/>
</head>
<style>
    .layui-table-cell{
        height:36px;
        line-height: 36px;
    }
</style>
<body>

<div class="layui-container">
    <br><br><br><br>

    <div class="layui-row layui-col-space10">

        <div class="layui-col-md3" >
<!--            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 15px;">
                <legend>活动状态添加</legend>
            </fieldset>
            <form  class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-input-inline" width="">
                        <input type="text" name="activitytype" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-input-inline" style="width:auto">
                        <button class="layui-btn" lay-submit="" lay-filter="formDemo" id="formDemo">新增</button>
                    </div>
                </div>
            </form>
            <table class="layui-table">
                <colgroup>
                    <col>
                    <col>
                </colgroup>
                <tbody id="table">
                </tbody>
            </table>-->
        </div>

        <div class="layui-col-md6" style="padding-top: 10px;">
            <!--数据表格-->
            <div>
                <table class="layui-hide" id="activityTypeTable" lay-filter="activityTypeTable"></table>
                <button class="layui-btn layui-btn-lg" id="jiesuan">结算</button>
            </div>
        </div>
        <div class="layui-col-md3" >

        </div>
    </div>
</div>



<script type="text/javascript" src="/resources/layui/layui.js"></script>

<script type="text/javascript">

    //提升数据表格的作用域，因为底下还有一个reloadTable方法
    var tableIns;
    var username1 = '[[${session.user.name}]]';

    layui.use(['jquery', 'form', 'layer','laydate', 'table'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var table = layui.table;
        var laydate = layui.laydate;

        var  tableIns = table.render({
            elem: "#activityTypeTable",
            title: "活动类型表格",
            url: "/car/loadAllCar",

            where:{username:username1},

            sort:true,
            //toolbar: "#activityToolBar",
            page: true,
            height: "full-180",
            cols: [ [
               // {type:'checkbox',fixed:'left'},
                //{field: 'id', title: 'ID', align: 'center',width:'50'},
                {field: 'goodsname', title: '商品名称', align: 'center',width:'299'},
                {field: 'price', title: '单价', align: 'center',width:'80'},
                {field: 'number', title: '数量', align: 'center',width:'80'},
                {field: 'username', hide: true}
                // {fixed: 'right', title: '操作', align: 'center',width:'150',templet: '#tableBar'}
            ]
            ],
            done: function (data, curr, count) {
                //不是第一页时，如果当前返回的数据为0那么就返回上一页
                if (data.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: curr - 1
                        }
                    })
                }
            }
        });

        $("#jiesuan").click(function () {
            var data = layui.table.cache["activityTypeTable"];
            console.log(data);
            var goodsname = '';var num=0;var price = 0;
            for (var i=0;i<data.length;i++) {
               goodsname +="{" +data[i].goodsname+"*"+data[i].number +"}";
               num+=data[i].number;
               price += Number(data[i].number)*Number(data[i].price);
            }
            $.post("/order/CreateOrder", {goodsname: goodsname, num: num, price: price},function (res) {
                if (res.code == 200) {
                    layer.msg("结算成功");
                }
            });
            for (var i=0;i<data.length;i++) {
                $.ajax({
                    type: "POST",
                    url: "/car/deleteCar",
                    data: {id:data[i].id},
                    async:false,
                    success: function(res){
                    }
                });
            }



        })




    });
/*



        form.on("submit(formDemo)",function (data) {
            console.log($('[name="activitytype"]').val());
            $.get("/activityType/addActivityType",{activitytype:$('[name="activitytype"]').val()},function (res) {
                refresh();
            });
        });



        //初始化
        $.get("/activityType/loadAllActivityType",function (res) {
            var data = res.data;
            var dom = $("#table");
            var html = '';
            $.each(data,function (index, item) {
                html += '<tr>';
                html += '<td>'+item.activitytype+'</td>';
                html += '<td><a class="layui-icon layui-icon-close" style="color:red" onclick="huoqu(\''+item.activitytype+'\')"></a></td>';
                html += '</tr>';
            })
            dom.html(html);
            //重新渲染下拉列表
            form.render("select");
        });
    });

    function huoqu(type) {
        layui.layer.confirm('你确定要删除【' + type + '】这个活动类型吗？', {icon: 3, title: '提示'}, function (index) {
            layui.jquery.post("/activityType/deleteActivity", {activitytype: type}, function (res) {
                if (res.code == 200) {
                    layui.layer.msg(res.msg);
                    layui.layer.close(index);
                    refresh();
                }

            });
        })
    }
    function refresh(){
        layui.jquery.get("/activityType/loadAllActivityType",function (res) {
            var data = res.data;
            var dom = layui.jquery("#table");
            var html = '';
            layui.jquery.each(data,function (index, item) {
                html += '<tr>';
                html += '<td>'+item.activitytype+'</td>';
                html += '<td><a class="layui-icon layui-icon-close" style="color:red" onclick="huoqu(\''+item.activitytype+'\')"></a></td>';
                html += '</tr>';
            })
            dom.html(html);
            //重新渲染下拉列表
            layui.form.render("select");
        });
    }
*/








</script>

</body>
</html>